----------------------------------Effect Variables--------------------------------------
EFFECT.effectID = 1 -- Whatever value you want as long as it doesn't override any other effects' IDs.
EFFECT.effectName = "Movement Speed Effect"
EFFECT.effectDuration = 0
EFFECT.effectCurrentStacks = 0
EFFECT.effectOldStacks = 0
EFFECT.effectMaxStacks = 1
EFFECT.effectFinished = false
---------------------------------------------------------------------------------------

function EFFECT:Init(pl, effname, mult, add, dur, maxstacks)
	if(pl.Effects != nil)then
		for k, v in pairs(pl.Effects)do
			if(v.effectName == effname and !v.RemoveMe)then
				v:AddStack()
				return v
			end
		end
	end
	self.effectName = effname
	self.effectDuration = dur
	self.effectValueAdded = 0
	self.effectMaxStacks = maxstacks
	self.effectCurrentStacks = 1
	self.effectOldStacks = 0
	self.DestroyTime = CurTime() + dur
	self.OldValue = pl:GetWalkSpeed()
	self.CurMult = mult
	self.CurAdd = add
	self.RemoveMe = false
	local a = table.Copy(self)
	if(pl.Effects == nil)then
		pl.Effects = {self}
	else
		table.insert( pl.Effects, a)
	end
	return a
end

function EFFECT:AddStack()
	self.DestroyTime = CurTime() + self.effectDuration
	if(self.effectCurrentStacks < self.effectMaxStacks)then
		print("adding one stack to "..self.effectOldStacks.."-"..self.effectCurrentStacks.."-"..self.effectMaxStacks.."")
		self.effectCurrentStacks = self.effectCurrentStacks + 1
	end
end

function EFFECT:Think(pl)
	if(!self.RemoveMe)then
		if(CurTime() >= self.DestroyTime)then
			print("Movement speed effect expired on "..pl:GetName().." with "..self.effectCurrentStacks.." stacks.")
			pl:SetWalkSpeed(pl:GetWalkSpeed()-self.effectValueAdded)
			self.effectOldStacks = 0
			self.effectCurrentStacks = 0
			self.RemoveMe = true
		end
		if((self.effectOldStacks < self.effectCurrentStacks))then
			pl:SetWalkSpeed(pl:GetWalkSpeed()-self.effectValueAdded)
			self.effectValueAdded = ((pl:GetWalkSpeed()*self.CurMult)+self.CurAdd)*self.effectCurrentStacks - pl:GetWalkSpeed()
			pl:SetWalkSpeed(pl:GetWalkSpeed()+self.effectValueAdded)
			self.effectOldStacks = self.effectCurrentStacks
			self.OldValue = pl:GetWalkSpeed()
		end
	end
end

function EFFECT:Remove()
	self.RemoveMe = true
end

function EFFECT:Reset(pl)

end




